import { Service } from 'egg';


export default class PetService extends Service {
  // 查找所有
  async selectAll() {
    const all = await this.app.mysql.select('pets', {});
    return all;
  }

  // 根据宠物名称模糊查找
  async selectLikeName(name: string) {
    const res = await this.app.mysql.query(
      `select * from pets where name like '%${name}%'`)
    return res
  }

  // 添加pet
  async addOne(pet) {
    const add = await this.app.mysql.insert('pets', pet);
    return add;
  }

  // 删除pet
  async delById(id) {
    const del = await this.app.mysql.delete('pets', {
      id
    })
    return del
  }

  // 修改pet
  async updateById(pet) {
    const update = await this.app.mysql.update('pets', {
      ...pet
    });
    return update
  }
}
